/**
 * related to repairInfo.ui
 * 
 * @Author : 2037630@163.com
 * @Timestamp : 2017-04-19
 */
var nf = sm("do_Notification");
var global = sm("do_Global");
var Controller = require("core/controller");
var log = require("util/log")
var datePick = sm("do_DateTimePicker");
var navigate = require("util/navigate")
var router = require("config/router")
var server = require('config/server');
var device=require("util/device")
var net = require("util/net");
var page = sm("do_Page");
var deviceMou=require("module/deviceModule")
var city = require("module/cityModule")
//var ar_promisMoney=ui('ar_promisMoney');
//var ar_nextFollow=ui('ar_nextFollow');
var common = require('util/common')
Controller({
	config: {
		name : "addRecord",
		header:{
			title:"添加外访记录",
			right:{
				text:"保存",
				handle:function(){
					if(this.data.adRecordList.follCust.length<1){
						log.info(989,deviceMou.isIOS)
						deviceMou.isIOS===true?nf.toast('姓名不能为空', 150, 850):nf.toast('姓名不能为空')
//						nf.toast('姓名不能为空', 150, 850)
//						nf.toast('姓名不能为空')
					}else if(this.data.adRecordList.ar_detailAddr.length<5){
						deviceMou.isIOS===true?nf.toast('详细地址长度不得少于5个字', 150, 850):nf.toast('详细地址长度不得少于5个字')
					}else if(this.data.arList.length<=0){
						deviceMou.isIOS===true?nf.toast('请上传外访材料', 150, 850):nf.toast('请上传外访材料')
					}else if(this.data.adRecordList.ar_inFlowInfo.length<5){
						deviceMou.isIOS===true?nf.toast('跟进内容长度不得少于5个字', 150, 850):nf.toast('跟进内容长度不得少于5个字')
					}else if(this.data.adRecordList.addPromis==1){
							if(this.data.adRecordList.ar_proMoney.length<=0){
								deviceMou.isIOS===true?nf.toast('请输入承诺还款金额', 150, 850):nf.toast('请输入承诺还款金额')
							}
							else if (this.data.adRecordList.promise_date.length<=0) {
								deviceMou.isIOS===true?nf.toast('请输入承诺还款日期', 150, 850):nf.toast('请输入承诺还款日期')
						}
//						else if(this.data.adRecordList.addFollowDate==1&&this.data.adRecordList.remind_date.length<=0){
//							nf.toast('请输入下次提醒还款日期')
//						}else if (this.data.adRecordList.addFollowDate==1&&this.data.adRecordList.ar_remindInfo<=5) {
//							nf.toast('提醒内容长度不得少于5个字')
//						}
//						else{
//							this.submitFwRecord()
//							log.info(7758)
//						}
							else if (this.data.adRecordList.addFollowDate==1) {
								if(this.data.adRecordList.remind_date.length<=0){
									deviceMou.isIOS===true?nf.toast('请输入下次跟进日期', 150, 850):nf.toast('请输入下次跟进日期')
								}else if (this.data.adRecordList.ar_remindInfo<=5) {
									deviceMou.isIOS===true?nf.toast('下次跟进提醒内容长度不得少于5个字', 150, 850):nf.toast('下次跟进提醒内容长度不得少于5个字')
							}else{
								this.submitFwRecord()
							}
							}
					}
					else if (this.data.adRecordList.addFollowDate==1) {
						if(this.data.adRecordList.remind_date.length<=0){
							deviceMou.isIOS===true?nf.toast('请输入下次跟进日期', 150, 850):nf.toast('请输入下次跟进日期')
						}else if (this.data.adRecordList.ar_remindInfo<=5) {
							deviceMou.isIOS===true?nf.toast('下次跟进提醒内容长度不得少于5个字', 150, 850):nf.toast('下次跟进提醒内容长度不得少于5个字')
					}else{
						this.submitFwRecord()
					}
					}
					else{
						this.submitFwRecord()
					}
				}
			}
		}
	},
	mapping : {
		"ar_obje.items" : "adRecordList.ar_obje|getTypeCodeData",
		"ar_obje.value" : "adRecordList.ar_objeValue",
		"ar_Prov.items" : "adRecordList.ar_Prov|getTypeCodeData",
		"ar_Prov.value" : "adRecordList.ar_ProvValue",
		"ar_City.items" : "adRecordList.ar_City|getTypeCodeData",
		"ar_City.value" : "adRecordList.ar_CityValue",
		"ar_Area.items" : "adRecordList.ar_Area|getTypeCodeData",
		"ar_Area.value" : "adRecordList.ar_AreaValue",
		"ar_adresType.items" : "adRecordList.ar_adresType|getTypeCodeData",
		"ar_adresType.value" : "adRecordList.ar_adresTypeValue",
		"ar_addresState.items" : "adRecordList.ar_addresState|getTypeCodeData",
		"ar_addresState.value" : "adRecordList.ar_addresStateValue",
		"ar_clFeedbk.items" : "adRecordList.ar_clFeedbk|getTypeCodeData",
		"ar_clFeedbk.value" : "adRecordList.ar_clFeedbkValue",
		"ar_userName.text":"adRecordList.follCust",
		"ar_inFlowInfo.text":"adRecordList.ar_inFlowInfo",
		"ar_proMoney.text":"adRecordList.ar_proMoney",
		"ar_remindInfo.text":"adRecordList.ar_remindInfo",
		"ar_detailAddr.text":"adRecordList.ar_detailAddr",
		"remind_date.text":"adRecordList.remind_date",
		"promise_date.text":"adRecordList.promise_date",
//		"aricon_pro.iconColor":"aricon_pro",
//		"aricon_next.iconColor":"aricon_next",
	},
	data : {
		adRecordList : {
			ar_obje: "0034",
			ar_objeValue: "145",
			ar_clFeedbk: "0031",
			ar_clFeedbkValue:"115",
			ar_Prov: "",
			ar_ProvValue: "",
			ar_City: "",
			ar_CityValue: "",
			ar_Area: "",
			ar_AreaValue: "",
			ar_adresType: "0024",
			ar_adresTypeValue:"88",
			ar_addresState:"0025",
			ar_addresStateValue:"93",
			ar_userName:"",
			ar_detailAddr:"",
			ar_inFlowInfo:"",
			ar_proMoney:"",
			ar_remindInfo:"",
			remind_date:"",
			promise_date:"",
			addPromis:"0",
			addFollowDate:"0",
//			aricon_pro:"",
//			aricon_next:"",
//			creator:page.getData().folred.creator,
//			cupoId:page.getData().folred.cupoId,
//			custId:page.getData().folred.custId,
			follCust:"",
//			follName:page.getData().folred.follName,
//			follOrderNum:page.getData().folred.follOrderNum,
//			reapId:page.getData().folred.reapId
		},
		arList:[]
	},
	ui:{
		ar_Prov:"ar_Prov",
		ar_City:"ar_City",
		ar_Area:"ar_Area",
		ar_layoutPromis:"ar_layoutPromis",
		ar_layoutRemind:"ar_layoutRemind",
		ar_promisMoney:"ar_promisMoney",
		ar_nextFollow:"ar_nextFollow",
		root:"$"
		
	},
	event : {
		'ar_promisMoney':{
			'touch':function(){
				this.openPromisTab()
			}
		},
		'ar_nextFollow':{
			'touch':function(){
				this.openNeTab()
			}
		},
		'layout_remind':{
			'touch':function(){
				var self = this
				datePick.show(
						type=1,
						function(dat, e) {
						if(dat.flag==1){
							log.info(989,dat.time)
							var time = parseInt(dat.time)
							self.data.adRecordList.remind_date=common.dateFormat(time, 'yyyy-MM-dd')
							self.refresh('$')
						}	
				})
			}
		},
		'layout_promise':{
			'touch':function(){
				var self = this
				datePick.show(
						type=1,
						function(dat, e) {
						if(dat.flag==1){
							var time = parseInt(dat.time)
							self.data.adRecordList.promise_date=common.dateFormat(time, 'yyyy-MM-dd')
							self.refresh('$')
						}	
				})
			}
		},
		'ar_upFile':{
			'touch':function(){
			    device.uploadImage({
			    	width: 480,
					height: 720,
			    	iscut:false,
			    	quality:100,
			    	scope:this
			    }, this.ar_upLoad)
			}
		}
	},
	
	methods : {
		ar_upLoad:function(path){
			this.data.arList.push(path.id)
		},
		openPromisTab:function(){
			if(this.ui.ar_layoutPromis.visible==true){
				this.data.adRecordList.addPromis=0
				this.ui.ar_layoutPromis.visible=false
				this.ui.ar_promisMoney.iconColor="#A9A9A9FF"
				this.ui.root.redraw()
//				this.ui.ar_layoutPrDate.visible=false
//				this.data.adRecordList.aricon_pro="#E4E4E4"
			}else{
				this.data.adRecordList.addPromis=1
//				this.data.adRecordList.aricon_pro="#0191DAFF"
				this.ui.ar_layoutPromis.visible=true
				this.ui.ar_promisMoney.iconColor="#0191DAFF"
				this.ui.root.redraw()
//				this.ui.ar_layoutPrDate.visible=true
			}
		},
		openNeTab:function(){
			if(this.ui.ar_layoutRemind.visible==true){
				this.data.adRecordList.addFollowDate=0
				this.ui.ar_layoutRemind.visible=false
				this.ui.ar_nextFollow.iconColor="#A9A9A9FF"
				this.ui.root.redraw()
			}else{
				this.data.adRecordList.addFollowDate=1
				this.ui.ar_layoutRemind.visible=true
				this.ui.ar_nextFollow.iconColor="#0191DAFF"
				this.ui.root.redraw()
			}
			
		},
		submitFwRecord : function() {
			log.info(545654145,this.data)
			
			net.send({
				server:server.organization.addFollowRecord,
				data:{
//						  "createTime": global.getTime("yyyy-MM-dd hh:mm:ss"),
//						  "creator": this.data.getFollw.folred.creator,
						  "cupoId": this.data.getFollw.folred.cupoId,
//						  "fullId":this.data.getFollw.folred.fullId,
						  "custId": this.data.getFollw.folred.custId,
						  "fileIds": this.data.arList,
						  "follAddrtype": this.data.adRecordList.ar_adresTypeValue,
//						  "follArea": "高新区",
						  "follAreaid": city.getCityId(this.ui.ar_Area),
//						  "follCity": "西安市",
						  "follCityid": city.getCityId(this.ui.ar_City),
						  "follContent": this.data.adRecordList.ar_inFlowInfo,
						  "follContype": this.data.adRecordList.ar_addresStateValue,
						  "follCust": this.data.adRecordList.follCust,
						  "follFeedback": this.data.adRecordList.ar_clFeedbkValue,
//						  "follId": "string",
						  "follIspromise": this.data.adRecordList.addPromis,//承诺
						  "follIswarn": this.data.adRecordList.addFollowDate,//提醒
						  "follLoad": 0,
						  "follName": this.data.adRecordList.follName,
//						  "follOpurl": "string",
//						  "follOrderNum": this.data.adRecordList.follOrderNum,
						  "follPdate": this.data.adRecordList.promise_date,
						  "follPhoneNum": this.data.adRecordList.ar_detailAddr,
						  "follPnum": this.data.adRecordList.ar_proMoney,
//						  "follProvance": "陕西",
						  "follProvid": city.getCityId(this.ui.ar_Prov),
//						  "follRecoderid": "string",
						  "follRectype": 70,
						  "follSource": 113,
						  "follTarget": this.data.adRecordList.ar_objeValue,
//						  "follTaskcallerid": "string",
//						  "follTaskid": "string",
						  "follTime": global.getTime("yyyy-MM-dd hh:mm:ss"),
						  "follType": 111,
						  "follWarndate": this.data.adRecordList.remind_date,
						  "follWarninfo": this.data.adRecordList.ar_remindInfo,
//						  "reapId": this.data.adRecordList.reapId
				},
				success:function(){	
					this.refresh('$')
					nf.toast("提交成功")
					navigate.back("6666")
				},
				error : function(data) {
					deviceMou.isIOS===true?nf.toast(data.reason, 150, 850):nf.toast(data.reason)
				},
				scope:this
			})
		}
	},
	loaded : function(data) {
		this.data.getFollw=data
		city.init(this.ui.ar_Prov,this.ui.ar_City,this.ui.ar_Area)
	},
})